From 61cb937e5e7e53246389f135ebc7f7c466173d4c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 9 May 2016 00:22:46 +0300 Subject: [PATCH] Simplify error printing --- src/cargo/lib.rs | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index b149c6386..b3c9c9bbe 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -35,7 +35,7 @@ use docopt::Docopt; use core::{Shell, MultiShell, ShellConfig, Verbosity, ColorConfig}; use core::shell::Verbosity::{Verbose}; use core::shell::ColorConfig::{Auto}; -use term::color::{BLACK, RED}; +use term::color::{BLACK}; pub use util::{CargoError, CliError, CliResult, human, Config, ChainError}; @@ -178,34 +178,23 @@ pub fn shell(verbosity: Verbosity, color_config: ColorConfig) -> MultiShell { } } -// `output` print variant error strings to either stderr or stdout. -// For fatal errors, print to stderr; -// and for others, e.g. docopt version info, print to stdout. -fn output(err: String, shell: &mut MultiShell, fatal: bool) { - let (std_shell, color, message) = if fatal { - (shell.err(), RED, Some("error:")) - } else { - (shell.out(), BLACK, None) - }; - let _ = match message{ - Some(text) => std_shell.say_status(text, err.to_string(), color, false), - None => std_shell.say(err, color) - }; -} - pub fn handle_error(err: CliError, shell: &mut MultiShell) { debug!("handle_error; err={:?}", err); let CliError { error, exit_code, unknown } = err; - let fatal = exit_code != 0; // exit_code == 0 is non-fatal error + // exit_code == 0 is non-fatal error, e.g. docopt version info + let fatal = exit_code != 0; let hide = unknown && shell.get_verbose() != Verbose; - if hide { - let _ = shell.err().say_status("error:", "An unknown error occurred", - RED, false); + + let _ignored_result = if hide { + shell.error("An unknown error occurred") + } else if fatal { + shell.error(&error) } else { - output(error.to_string(), shell, fatal); - } + shell.say(&error, BLACK) + }; + if !handle_cause(&error, shell) || hide { let _ = shell.err().say("\nTo learn more, run the command again \ with --verbose.".to_string(), BLACK); -- 2.30.2